/*
 * scoreMatrix.h
 *
 *  Created on: 2011-08-31
 *      Author: pawel
 */
/**
 * This class loads score matrix from file.
 * It uses perl parser calling from C++ code
 */
#ifndef SCOREMATRIX_H_
#define SCOREMATRIX_H_

#include <stdexcept>
#include<boost/unordered_map.hpp>
//#include<string>
#include"enumTypes.h"
namespace bpp{
class Alphabet;
}
class scoreMatrix {
private:
	bpp::Alphabet *alphabet;
	size_t alphabetSymbolsTypes;
	/*
	 * Score matrix
	 */
 char **matrix;
 /*
  * Size of matrix(square matrix)
  */
 size_t size;
 /*
  * Maps connect Letters from alphabet to columns/rows in matrix
  */
 boost::unordered_map<char,int> colnames;
 boost::unordered_map<char,int> rownames;
/**
 *Contain features of matrix
 */
 bool EntropyValid;
 double entropy;
 bool ExpectedScoreValid;
 double expectedScore;
 bool ScaleValid;
 double scale;
 bool HighestScoreValid;
 char highestScore;
 bool LowestScoreValid;
 char lowestScore;
 bool LambdaValid;
 double lambda;
 bool HValid;
 double H;
/*
 * Loads matrix from file
 * @param filename - name of score matrix file
 * @param type - Type of alphabet
 * uses perl Parser
 */
 int loadMatrix(const std::string filename,const AlphabetType type)throw(std::logic_error);
 /**
  * Get size of matrix
  * uses perl parser
  */
 int getSize();
 /*
  * Fill row of matrix with scores
  * uses perl parser
  * @param row - row number
  * @param rowptr - ptr to matrix row
  */
 int fillRow(size_t row,char* rowptr);
 /*
  * get names of rows
  * Name is alphabet symbol
  * uses perl parser
  */
 int getRowNames();
 /*
   * get names of columns
   * Name is alphabet symbol
   * uses perl parser
   */
 int getColNames();
 /*
  * Loads score matrix entropy
  * uses perl parser
  */
 int loadEntropy();
 /*
  * Loads score matrix expected score
  * uses perl parser
  */
 int loadExpectedScore();
 /*
   * Loads score matrix scale
   * uses perl parser
   */
 int loadScale();
 /*
   * Loads score matrix highest score
   * uses perl parser
   */
 int loadHighestScore();
 /*
   * Loads score matrix lowest
   * uses perl parser
   */
 int loadLowestScore();
 /*
   * Loads score matrix lambda parameter
   * uses perl parser
   */
 int loadLambda();
 /*
   * Loads score matrix H parameter
   * uses perl parser
   */
 int loadH();

public:
	/*
	 * Constructor
	 *
	 */
	scoreMatrix(const std::string filename,const AlphabetType type);
	/*
	 * Fake object construktor DEEBUG only;
	 */
	scoreMatrix(std::string filename, AlphabetType type,bool fake);
	~scoreMatrix();
	/*
	 * Get score from matrix[a][b]
	 */
	char getScore(int a,int b);
	/*
	 * get matrix pointer in order to get scores (faster way than) char getScore(int a,int b)
	 * use carefully
	 *
	 */
	char** getMatrix();
	/*
	 * Fuctions below return state of matrix params
	 * Per parser can return undef value when can not parse parameter
	 * if returned value is false perl function return undef value
	 */
	bool isEntropyValid()const;
	bool isExpectedScoreValid()const;
	bool isScaleValid()const;
	bool isHighestScoreValid()const;
	bool isLowestScoreValid()const;
	bool isLambdaValid()const;
	bool isHValid()const;

	/*
	 * Functions below return value of parameter if defined
	 * else return 0
	 */
	 double getEntropy()const;
	 double getExpectedScore()const;
	 double getScale()const;
	 char getHighestScore()const;
	 char getLowestScore()const;
	 double getLambda()const;
	 double getH()const;
};

#endif /* SCOREMATRIX_H_ */
